package second.dao.impl;


import org.apache.commons.dbutils.QueryRunner;
import second.dao.UserDao;
import second.domain.User;
import second.utils.DataSourceUtils;

import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    @Override
    public void add(User user) {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        Object[] params={user.getUsername(),user.getPassword(),user.getEmail(),user.getGender(),user.getFlag(),user.getRole(),user.getCode()};
        try {
            qr.update("insert into tb_user (username,password,email,gender,flag,role,code) values(?,?,?,?,?,?,?)",params);
        } catch (SQLException e) {
            e.printStackTrace();
            throw  new RuntimeException("添加失败", e);
        }
    }
}
